package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 反射操作私有方法
 */
public class ReflectDemo6 {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        Person p = new Person();
//        p.dosome();//类外部不可以访问私有方法

        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();

        Method method = cls.getDeclaredMethod("dosome");
        method.setAccessible(true);//强制设置为可访问
        method.invoke(obj);

    }
}





